package com.rocketmq.temp3.common.support;

import org.springframework.context.SmartLifecycle;

public abstract class BeanLifecycle implements SmartLifecycle {
    //region spring容器初始化完成之后执行
    protected void initMethod() {
    }

    protected void destroyMethod() {
    }
    //endregion

    //region SmartLifecycle
    private boolean runState = false;

    //step 3
    @Override
    public final boolean isRunning() {
        return this.runState;
    }

    //step 5
    @Override
    public final void start() {
        this.initMethod();
        runState = true;
    }

    //step 7
    @Override
    public final void stop() {
        this.destroyMethod();
        this.runState = false;
    }

    //step 1 & 4
    @Override
    public final boolean isAutoStartup() {
        return true;
    }

    //step 6
    @Override
    public final void stop(Runnable callback) {
        this.stop();
        callback.run();
    }

    //step 2
    @Override
    public final int getPhase() {
        return Integer.MAX_VALUE;
    }
    //endregion
}
